﻿ 
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace wpf.Triage.Convert
{
    [ValueConversion(typeof(string), typeof(bool))]
    public class RadioSettingsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return false;
            var checkvalue = value.ToString();
            var targetvalue = parameter.ToString();
            var r = checkvalue.Equals(targetvalue,
                StringComparison.InvariantCultureIgnoreCase);
            return r;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return null;
            var usevalue = (bool)value;
            if (usevalue)
                return parameter.ToString();
            return DependencyProperty.UnsetValue;
        }
    }

    [ValueConversion(typeof(string), typeof(bool))]
    public class RadioVisibleSettingsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return false;
            var checkvalue = value.ToString();
            var targetvalue = parameter.ToString();
            if (checkvalue.Equals(targetvalue, StringComparison.InvariantCultureIgnoreCase))
            {
                return Visibility.Visible;
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return null;
            var usevalue = (bool)value;
            if (usevalue)
                return parameter.ToString();
            return DependencyProperty.UnsetValue;
        }
    }
     
}